package com.rran.study.designpattern.behavioral.command.command;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 复合命令
 */
public class CompositeCommand implements Command {

    private Queue<Command> queue = new LinkedList<>();

    public void addCommand(Command command) {
        queue.add(command);
    }

    public void removeCommand(Command command){
        queue.remove(command);
    }

    @Override
    public void execute() {
        while (!queue.isEmpty()) {
            Command poll = queue.poll();
            poll.execute();
        }
    }
}
